package com.itwlj.mapper;

import com.github.pagehelper.Page;
import com.itwlj.dto.OrderPageQueryDTO;
import com.itwlj.entity.Order;
import com.itwlj.entity.OrderGoods;
import com.itwlj.vo.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    /**
     * 订单分页查询
     *
     * @param orderPageQueryDTO
     * @return
     */
    Page<OrderVO> pageQuery(OrderPageQueryDTO orderPageQueryDTO);

    /**
     * 订单批量删除(逻辑删除)
     *
     * @param ids
     * @param isDelete
     */
    void softDeleteBatch(List<Long> ids, Integer isDelete);

    /**
     * 根据id修改商品
     *
     * @param order
     */
    void update(Order order);

    /**
     * 新增订单
     *
     * @param order
     */
    void insert(Order order);

    /**
     * 新增订单商品
     *
     * @param orderGoods
     */
    @Insert("insert into order_goods(order_id, sku_id,name, attrs_text, picture, price, count) VALUES (#{orderId},#{skuId},#{name},#{attrsText},#{picture},#{price},#{count})")
    void insertOrderGoods(OrderGoods orderGoods);

    /**
     * 根据id查询订单
     *
     * @param id
     * @return
     */
    @Select("select * from `order` where id = #{id}")
    Order getById(Long id);

    /**
     * 根据订单id查询订单商品
     *
     * @param orderId
     * @return
     */
    @Select("select id, order_id,sku_id, name, attrs_text, picture, price, count from order_goods where order_id = #{orderId}")
    List<OrderGoods> getOrderGoods(Long orderId);

    /**
     * 根据动态条件统计营业额数据
     *
     * @param map
     * @return
     */
    Double sumByMap(Map map);

    /**
     * 根据动态条件统计订单数量
     *
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 根据订单状态和创建时间查询订单
     *
     * @param status
     * @param createTime
     * @return
     */
    @Select("select * from `order` where order_state = #{status} and create_time < #{createTime}")
    List<Order> getByStatusAndCreateTimeLT(Integer status, LocalDateTime createTime);
}
